package com.yanyilu.qiubite.service;

import com.yanyilu.qiubite.entity.Gift;
import com.yanyilu.qiubite.jpa.GiftJpa;
import com.yanyilu.qiubite.jpa.SpotJpa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GiftService {
    @Autowired
    GiftJpa giftJpa;

    @Autowired
    SpotJpa spotJpa;

    //奖品列表
    public List<Gift> spotGiftList(Example<Gift> example, Pageable pagesable){
        return giftJpa.findAll(example,pagesable).getContent();
    }

    // 添加/更新 景区
    public void giftSave(Gift gift){
        Integer spotId = gift.getSpotId();
        String spotName = spotJpa.findSpotNameBySpotId(spotId);
        gift.setSpotName(spotName);
        giftJpa.save(gift);
    }

    public void giftDeleteById(Integer giftId){
        giftJpa.deleteById(giftId);
    }
}
